const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    index: 0,
    index2: 0,
    index3: 0,
    index4: 0,
    index5: 0,
    index6: 0,
    year: ['请选择年份'],
    dishi: ['请选择地市'],
    xueli: ['请选择报名学历'],
    leibie: ['请选择心仪岗位类别'],
    dengji: ['请选择心仪岗位等级'],
    danwei: ['请选择心仪单位'],
    viewShowed: false, //显示结果view的状态
    phone: 0,
    theList: '',
    page: 69
  },

      
  bindPickerChange: function (e) {
    let num = e.detail.value;
    let that = this;
    console.log('year发送选择改变,携带值为', that.data.year[num]);
    this.setData({
      index: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'nianfen',
        grtext: that.data.year[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].shi)
        }
        that.setData({
          dishi: list
        });
      }
    })
  },
  bindPickerChange2: function (e) {
    let num2 = e.detail.value;
    let that = this;
    console.log('dishi发送选择改变,携带值为', that.data.dishi[num2]);
    this.setData({
      index2: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'shi',
        grtext: that.data.dishi[num2],
        onefiled: 'nianfen',
        onetext: that.data.year[this.data.index]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].xueli)

        }
        that.setData({
          xueli: list
        });
      }
    })
  },
  bindPickerChange3: function (e) {
    let num3 = e.detail.value;
    let that = this;
    console.log('xueli发送选择改变,携带值为', that.data.xueli[num3]);
    this.setData({
      index3: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '4',
        grfiled: 'xueli',
        grtext: that.data.xueli[num3],
        onefiled: 'nianfen',
        onetext: that.data.year[this.data.index],
        twofiled: 'shi',
        twotext: that.data.dishi[this.data.index2],
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].leibie)
        }
        that.setData({
          leibie: list
        });
      }
    })
  },
  bindPickerChange4: function (e) {
    let num4 = e.detail.value;
    let that = this;
    console.log('leibie发送选择改变,携带值为', that.data.leibie[num4]);
    this.setData({
      index4: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '5',
        grfiled: 'leibie',
        grtext: that.data.leibie[num4],
        onefiled: 'nianfen',
        onetext: that.data.year[this.data.index],
        twofiled: 'shi',
        twotext: that.data.dishi[this.data.index2],
        threefiled: 'xueli',
        threetext: that.data.xueli[this.data.index3],
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].dengji)
        }
        that.setData({
          dengji: list
        });
      }
    })
  },
  bindPickerChange5: function (e) {
    let num5 = e.detail.value;
    let that = this;
    console.log('dengji发送选择改变,携带值为', that.data.dengji[num5]);
    this.setData({
      index5: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '6',
        grfiled: 'dengji',
        grtext: that.data.dengji[num5],
        onefiled: 'nianfen',
        onetext: that.data.year[this.data.index],
        twofiled: 'shi',
        twotext: that.data.dishi[this.data.index2],
        threefiled: 'xueli',
        threetext: that.data.xueli[this.data.index3],
        fourfiled: 'leibie',
        fourtext: that.data.leibie[this.data.index4],
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].danwei)
        }
        that.setData({
          danwei: list
        });
      }
    })
  },
  bindPickerChange6: function (e) {
    let num6 = e.detail.value;
    let that = this;
    console.log('danwei发送选择改变,携带值为', that.data.danwei[num6]);
    this.setData({
      index6: e.detail.value
    })
  },

  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=42519&callback=?', //接收url
      data: {
        level: '1',
        nianfen: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace('(', '');
        jsonStr = jsonStr.replace(')', '');
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        list.push('请选择年份')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].nianfen)
        }
        that.setData({
          year: list
        });
      }
    })
  },
  tijiao: function (res) {
    var that = this;
    var year = that.data.year[that.data.index];
    var dishi = that.data.dishi[that.data.index2];
    var xueli = that.data.xueli[that.data.index3];
    var leibie = that.data.leibie[that.data.index4];
    var dengji = that.data.dengji[that.data.index5];
    var danwei = that.data.danwei[that.data.index6];
    console.log(this.data)
    var phone = wx.getStorageSync('kqcxphone')
    if (phone) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/getlist/?actid=42519&callback=?',
        data: {
          nianfen: year,
          shi: dishi,
          xueli: xueli,
          leibie: leibie,
          dengji:dengji,
          danwei:danwei,
          limits: '100'
        }, //接收参数
        success(res) { //返回
          var jsonStr = res.data;
          jsonStr = jsonStr.replace('(', '');
          jsonStr = jsonStr.replace(')', '');
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          };
          // console.log(theJson)
          if(theJson.status==2)
          {
            that.setData({
              theList: ''
            })
            wx.showToast({
              title: '无对应岗位',
              duration: 2000,
              icon: 'none'
            })
          }
          that.setData({
            theList: theJson.lists
          })
          // console.log(that.data.theList)
        }
      })
    } else {
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      })
      that.setData({
        fixed: 1
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('kqcxphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=42519&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace('(', '');
          jsonStr = jsonStr.replace(')', '');
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ''); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          that.setData({
            fixed: !1
          })
        }
      })
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 37,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },
  lingqu(){
    wx.navigateTo({
      url: '../../web1/web1' ,
    })
  },




















  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})